prepare(" SELECT COUNT(*) as correct_count FROM student_answers WHERE session_id = ? AND is_correct = 1 "); $stmt->execute([$session_id]); return $stmt->fetch(PDO::FETCH_ASSOC)['correct_count']; } function get_exam_details($exam_id, $pdo) { try { $stmt = $pdo->prepare(" SELECT e.*, s.name as subject_name FROM exams e LEFT JOIN subjects s ON e.subject_id = s.id WHERE e.id = ? "); $stmt->execute([$exam_id]); return $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { // If the join fails, try without the subject join $stmt = $pdo->prepare("SELECT * FROM exams WHERE id = ?"); $stmt->execute([$exam_id]); $exam = $stmt->fetch(PDO::FETCH_ASSOC); if ($exam) { $exam['subject_name'] = 'General'; } return $exam; } } /** * Validate phone number */ function validate_phone($phone) { // Remove all non-digit characters $cleaned = preg_replace('/\D/', '', $phone); // Basic validation - adjust based on your requirements if (strlen($cleaned) < 10) { return false; } return true; } /** * Format percentage with color coding */ function format_percentage($percentage) { if ($percentage >= 80) { return '' . number_format($percentage, 1) . '%'; } elseif ($percentage >= 60) { return '' . number_format($percentage, 1) . '%'; } elseif ($percentage >= 40) { return '' . number_format($percentage, 1) . '%'; } else { return '' . number_format($percentage, 1) . '%'; } } /** * Get performance level */ function get_performance_level($percentage) { if ($percentage >= 80) return 'Excellent'; if ($percentage >= 70) return 'Very Good'; if ($percentage >= 60) return 'Good'; if ($percentage >= 50) return 'Average'; if ($percentage >= 40) return 'Pass'; return 'Fail'; } // ... existing functions ... // ... other existing functions ... ?>